<template>
  <div id="selectionlist" class="task">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item>待办理事项</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <el-radio-group v-model="taskflag" @change="radioChange" style="margin:15px">
        <el-radio-button label="待办理事项列表">
        </el-radio-button>
        <el-radio-button label="已办理事项列表">
        </el-radio-button>
      </el-radio-group>
      <el-table :data="tasklist" highlight-current-row v-loading="listLoading" style="width: 100%;border-top: 1px solid #95B8E7;" :height="tableHeight" border id="tasklist">
        <el-table-column prop="step" label="环节" align="right" width="300px">
        </el-table-column>
        <el-table-column label="待办" align="left">
          <template slot-scope="scope">
            <div v-if="scope.row.step==='动议'">
              <span v-if="scope.row.processingPersons===0">{{scope.row.processingPersons}}人</span>
              <el-button v-else @click="detail(scope.row.step)" type="primary">{{scope.row.processingPersons}}人</el-button>
            </div>
            <div v-else-if="scope.row.step==='廉政谈话'||scope.row.step==='任职谈话'||scope.row.step==='宣布'">
              <span v-if="scope.row.processedPersons===0">{{scope.row.processedPersons}}人</span>
              <el-button v-else @click="detail(scope.row.step)" type="primary">{{scope.row.processedPersons}}人</el-button>
              <!-- <el-button @click="detail(scope.row.step)" type="primary">{{scope.row.processedPersons}}人</el-button> -->
            </div>
            <div v-else-if="scope.row.step==='讨论决定'||scope.row.step==='公示'||scope.row.step==='报中组部备案'||scope.row.step==='任职发文'||scope.row.step==='征求协管方意见'">
              <span v-if="scope.row.processingPersons+scope.row.approvePersons===0">0人</span>
              <el-button v-else @click="detail(scope.row.step)" type="primary">{{scope.row.processingPersons+scope.row.approvePersons}}人</el-button>
            </div>
            <div v-else>
              <span v-if="scope.row.approvePersons===0">{{scope.row.approvePersons}}人</span>
              <el-button v-else @click="detail(scope.row.step)" type="primary">{{scope.row.approvePersons}}人</el-button>
              <!-- <el-button @click="detail(scope.row.step)" type="primary">{{scope.row.approvePersons}}人</el-button> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      taskflag: '待办理事项列表',
      tasklist: [],
      totalnum: 0,
      pageNum: 1,
      pageSize: 20,
      listLoading: false,
      changeSizeFlag: false,
      unitName: '',
      tableHeight: 100
    }
  },
  methods: {
    radioChange () {
      if (this.taskflag === '已办理事项列表') {
        this.$router.push({path: '/selection/sendofflist'})
      }
    },
    detail (step) {
      if (step === '动议') {
        this.$router.push({path: '/selection/dongyilist'})
      }
      if (step === '事前报告') {
        this.$router.push({path: '/selection/candidateReportCn'})
      }
      if (step === '凡提四必') {
        this.$router.push({path: '/selection/necessary/leaderlist'})
      }
      if (step === '民主推荐') {
        this.$router.push({path: '/selection/tuijiancn'})
      }
      if (step === '考察') {
        this.$router.push({path: '/selection/kaochacn'})
      }
      if (step === '讨论决定') {
        this.$router.push({path: '/selection/taoluncn'})
      }
      if (step === '公示') {
        this.$router.push({path: '/selection/gongshisz'})
      }
      if (step === '征求协管方意见') {
        this.$router.push({path: '/selection/manageOpinionCn'})
      }
      if (step === '报中组部备案') {
        this.$router.push({path: '/selection/baobeicn'})
      }
      if (step === '任职发文') {
        this.$router.push({path: '/selection/fawencn'})
      }
      if (step === '任职谈话') {
        this.$router.push({path: '/selection/tanhuacn'})
      }
      if (step === '廉政谈话') {
        this.$router.push({path: '/selection/tanhuacn2'})
      }
      if (step === '宣布') {
        this.$router.push({path: '/selection/xuanbucn'})
      }
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    getList () {
      this.unitName = localStorage.getItem('unitName')
      let departmentCodes = []
      departmentCodes = [1, 2, 3]
      let para = {
        departmentCode: departmentCodes
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.selectionAPI + `api/selection/home/getUserTaskCountAtAllSteps`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            console.log('num' + response.data.result.length)
            let tasks = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (this.unitName === '干部监督处') {
                if (response.data.result[i].step === '凡提四必' || response.data.result[i].step === '公示') { // 主管监督处副司长有凡提四必和公示的权限
                  tasks.push(response.data.result[i])
                }
              } else {
                // 主管干部处副司长有凡提四必和公示外其他环节的权限，此处避免重复添加动议
                if (response.data.result[i].step !== '凡提四必' && response.data.result[i].step !== '公示') {
                  tasks.push(response.data.result[i])
                }
              }
            }
            this.tasklist = tasks
            this.changeSizeFlag = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 250
      })
    }
  },
  mounted () {
    this.getList()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  #selectionlist #tasklist .is-right {
    text-align: right !important;
  }
  #selectionlist #tasklist .is-left {
    text-align: left !important;
  }
  #selectionlist #tasklist .cell i{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: center;
    display: block;
    cursor: pointer;
    margin:0;
  }
  #selectionlist #tasklist .cell{
    font-size:var(--size20) !important;
    font-family:'Microsoft YaHei';
  }
  .task .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
    border-right: #95B8E7 solid 1px;
    border-bottom: #95B8E7 solid 1px;
    min-height: 30px;
    line-height:30px;
  }
  .task .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体';
    text-align:center
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #selectionlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #selectionlist .el-table__row{
    height: 50px;
  }
  #selectionlist #legent{
    float:right;
    margin-right: 20px;
  }
  #selectionlist #legent div{
    float:left;
    line-height: 42px;
    font-size:var(--size14);
  }
  #selectionlist #legent i{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: left;
    display: block;
    margin:5px 5px 0 10px;
  }
  #selectionlist .cell i{
    background-position: center center;
    background-repeat: no-repeat;
    float: center;
    display: block;
    cursor: pointer;
    margin:0 auto;
  }
</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
